package com.threeti.mecool.legacy.domain.model.basicdata;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;

public class MDCategory {
    private String code;
    private String alias;
    private String memo;
    private MDCustomer customer;
    private Set<MDBrand> brands = new LinkedHashSet<MDBrand>();

    public MDCategory(String code, String alias, String memo, MDCustomer customer) {
        this.code = code;
        this.alias = alias;
        this.memo = memo;
        this.customer = customer;
        customer.addCategory(this);
    }

    void addBrands(MDBrand brand) {
        brands.add(brand);
    }

    public String getCode() {
        return code;
    }

    public String getAlias() {
        return alias;
    }

    public String getMemo() {
        return memo;
    }

    public MDCustomer getCustomer() {
        return customer;
    }

    public Collection<MDBrand> getBrands() {
        return Collections.unmodifiableCollection(brands);
    }

    @Override
    public int hashCode() {
        return code != null ? code.hashCode() : super.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this) return true;
        if (code != null && obj instanceof MDCategory) {
            return code.equals(((MDCategory) obj).code);
        }
        return false;
    }
}
